﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using YTBZ.PUB.Common;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace YTBZ.PUB
{
    public partial class Default : MasterBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //BasePage.Check_Session("");
            if (!IsPostBack)
            {
                //Literal1.Text = "<script  type=\"text/javascript\" src=\"/WinValidatorFiles/" + position + "/js/MaxLenghtvalidator.js\"></script>";
                #region 递归页面里所有的TextBox
                InitialControl(MainContent.Controls);
                

                #endregion
            }
        }
        #region 递归页面里所有的TextBox
        private void InitialControl(ControlCollection objControlCollection)
        {

            foreach (System.Web.UI.Control objControl in objControlCollection)
            {
                if (objControl.HasControls())
                {
                    InitialControl(objControl.Controls);
                }
                else
                {
                    if (objControl is System.Web.UI.WebControls.TextBox)
                    {
                        TextBox tb = objControl as TextBox;
                        if (tb.MaxLength > 0 && tb.ReadOnly != true && tb.Enabled != false)
                        {
                            if (tb.Attributes["Search"] == null)
                            {
                                tb.Attributes.Add("length", tb.MaxLength.ToString());
                                if (tb.ToolTip == "")
                                    tb.ToolTip = "长度不能大于" + tb.MaxLength.ToString() + "个字或字符";
                            }
                        }
                        if (tb.Attributes["SqlKey"] == null)
                        {
                            Sqlbaoliuziduan(tb);
                        }
                    }
                    else if (objControl is System.Web.UI.WebControls.Button)
                    {
                        Button tb = objControl as Button;
                        //默认enter是查询按钮

                        //if (tb.ID == "btnCX")
                        //{
                        //    this.form1.DefaultButton = tb.UniqueID;
                        //}

                        //if (tb.ID == "btnSel")
                        //{
                        //    this.form1.DefaultButton = tb.UniqueID;
                        //}

                        //if (tb.ID == "btnSearch")
                        //{
                        //    this.form1.DefaultButton = tb.UniqueID;
                        //}

                        if (tb.ID == "btnAdd" || tb.ID == "btnSave" || tb.ID == "btnUpdate" || tb.ID == "btnSubmit"  || tb.ID == "btn_add" )
                        {
                            if (tb.CausesValidation)
                                StringHelper.SetUIStyle(Page, tb);
                        }

                    }

                }
            }
        }
        #endregion
        /// <summary>
        /// 数据库保留字段
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        void Sqlbaoliuziduan(TextBox tb)
        {
            string sql = "'";
            string m_sql = "’";
            string[] sqlarr = sql.Split(',');
            string[] m_sqlarr = m_sql.Split(',');
            for (int i = 0; i < sqlarr.Length; i++)
            {
                tb.Text = tb.Text.Replace(sqlarr[i], m_sqlarr[i]);
            }

        }
   
    }
}